<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;

class DemoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'type' => 'required',
            'area' => 'required',
            'budget' => 'required',
            'name' => 'required',
            'community' => 'required',
            'fitment' => 'required',
            'few_room' => 'required',
            'phone' => 'required',
        ];
    }

    public function messages(){
        return [
            'type.required' => '房产类型必须',
            'area.required' => '房子面积必须',
            'budget.required' => '房子预算必须',
            'name.required' => '姓名必须',
            'community.required' => '小区必须',
            'fitment.required' => '装修要求必须',
            'few_room.required' => '房型必须',
            'phone.required' => '手机号必须',
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw (new HttpResponseException(response()->json([
            'status_code' => '500',
            'message' => '请求错误',
            'data' => $validator->errors()->first(),
        ],200)));
    }
}
